package com.arch.hdfs;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;

/**
 * @author pizhihui
 * @date 2024-06-03 10:03
 */
public class ReadFileDemo {


    public static void main(String[] args) throws IOException {

        System.setProperty("HADOOP_USER_NAME", "biadmin");

        Configuration conf = new Configuration();
        conf.addResource("core-site.xml");
        conf.addResource("hdfs-site.xml");

        FileSystem fs = FileSystem.get(conf);

        Path path = new Path("/tmp/data/res.txt");
        // FSDataOutputStream fsDataOutputStream = fs.create(path);

        FSDataInputStream input = fs.open(path);

        byte[] data = new byte[1024];
        while(input.read(data) != -1){
            System.out.println("读取到的数据是: " + new String(data));
        }

        // 关闭
        input.close();
        fs.close();


    }

}
